package com.book.notice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.book.notice.entity.Notice;
import com.book.notice.mapper.NoticeMapper;
import com.book.notice.service.NoticeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class NoticeServiceImp extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    @Autowired
    NoticeMapper noticeMapper;

    @Override
    public List<Notice> findNotice(Notice notice) {
        QueryWrapper<Notice> queryWrapper = new QueryWrapper();
        if (StringUtils.isNotEmpty(notice.getStatus())) {
            queryWrapper.eq("status", notice.getStatus());
        }
        if (StringUtils.isNotEmpty(notice.getMessagestatus())) {
            queryWrapper.eq("messagestatus", notice.getMessagestatus());
        }
        if (StringUtils.isNotEmpty(notice.getMessage())) {
            queryWrapper.eq("message", notice.getMessage());
        }
        return noticeMapper.selectList(queryWrapper);
    }

    @Override
    public List<Notice> getNoticeById(String[] ids) {
        List<String> list = Arrays.asList(ids);
        return (List<Notice>) this.listByIds(list);
    }

    @Override
    public void addNotice(Notice notice) {
        this.save(notice);
    }

    @Override
    public void update(Notice notice) {
        this.saveOrUpdate(notice);
    }
}
